<?php
namespace jy_peimilk;
defined('BY_JYA') or exit('error');
/*
*/
class notice extends \plugin{
	public function gettpl_data($orderid,$type=0){//type=0表单订单，type=1
		return false;
	}
	/*
		配送员新任务通知
	*/
	public function notice_orderget($order_id,$url=''){
		//新配送任务通知给配送员
		$order=pdo_get('jy_weishop_order',array('id'=>$order_id));
		$goods=pdo_get('jy_weishop_order_goods',array('orderid'=>$order_id));
		$goods['title']=pdo_getcolumn('jy_weishop_goods',array('id'=>$goods['goodsid']),'title');
		$address=pdo_get('core_address',array('id'=>$order['addressid']),array('pcd','address','mobile'));
		$address['pcd']=json_decode($address['pcd'],true);
		$address=$address['pcd']['province'].' '.$address['pcd']['city'].' '.$address['pcd']['district'].' '.$address['pcd']['street'].''.$address['address'];
		$template_id=cfc('account')->get_tpl_template_id('OPENTM416739152','新配送任务通知');
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('17468',[1,2,3,7],'orderget','新配送任务通知','jy_peimilk');
		}
		$message=array(
			'first'=>array('value'=>'新配送任务通知',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>date('Y/m/d H:i:s',$order['createtime']),"color" => "#4a5077"),
			'keyword3'=>array('value'=>$goods['title'],"color" => "#4a5077"),
			'keyword4'=>array('value'=>$address,"color" => "#4a5077"),
			'remark'=>array('value'=>'您有新的配送订单！请及时处理！点击“详情”查看订单信息。',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$order['ordersn']),
			array('value'=>date('Y/m/d H:i:s',$order['createtime'])),
			array('value'=>$goods['title']),
			array('value'=>$address),
		);
		if(!$url){
			$url=custom_url('jy_peimilk/worker_order/detail/id='.$order['id'],true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['peisong_id'],$template_id,$message,$url,'orderget','jy_peimilk',$order_id);
		}
		if($_SESSION['wxapp_id']){
			$url='/jy_peimilk/worker_order/detail/index?id='.$order['id'];
			$template_id=cfc('wxapp_api')->checktplNotice($order['peisong_id'],$wxapptemplate_id,$wxappmsg,$url,'orderget','jy_peimilk',$order_id);
		}
	}
	public function notice_pei2buyer($sendlog,$url=''){
		//订单配送提醒
		$template_id=cfc('account')->get_tpl_template_id('OPENTM405637366','订单配送提醒');
		$wxapp_id=$sendlog['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($sendlog['buymid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api',$wxapp_id)->get_tpl_template_id('31339',[2,3],'pei2buyer','订单配送提醒','jy_weishop');
		}
		$sendlog['goodsinfo']='';
		$sendlog['goods']=json_decode($sendlog['goods'],true);
		foreach($sendlog['goods'] as &$gv){
				$gv['title']=cfc('tools')->substr($gv['title'],0,6);
				$sendlog['goodsinfo'] .=$gv['title'];
				if($gv['selespename']){
					$sendlog['goodsinfo'] .='['.$gv['selespename'].']';
				}
				if($gv['leititle']){
					$sendlog['goodsinfo'] .='['.$gv['leititle'].']';
				}
				$sendlog['goodsinfo'] .="(".$gv['num'].")；";
				$gv['unit']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),'unit');
		}
		$times=$sendlog['day'].' '.$sendlog['times'];
		$message=array(
			'first'=>array('value'=>'您好!您的商品正在配送中,请您保持手机的通畅。',"color" => "#4a5077"),
			'keyword1'=>array('value'=>'SN'.$sendlog['id'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$times,"color" => "#4a5077"),
			'keyword3'=>array('value'=>$sendlog['goodsinfo'],"color" => "#4a5077"),
			'remark'=>array('value'=>'请耐心等候！如有疑问请联系在线客服！',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$times),
			array('value'=>$sendlog['goodsinfo']),
		);
		if(!$url){
			$url='jy_peimilk/member.sendlog/';
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($sendlog['buymid'],$template_id,$message,$url,'pei2buyer','jy_weishop',$sendlog['id']);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_peimilk/member/sendlog/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($sendlog['buymid'],$wxapptemplate_id,$wxappmsg,$url,'pei2buyer','jy_weishop',$sendlog['id']);
		}
	}
	public function notice_receive2buyer($sendlog){
		//发送订单收货通知给买方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM202314085','订单确认收货通知');
		$wxapp_id=$sendlog['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($sendlog['buymid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('31042',[1,2,4,10,7],'receive2buyer','订单确认收货通知','jy_weishop');
		}
		$sendlog['goodsinfo']='';
		$sendlog['goods']=json_decode($sendlog['goods'],true);
		foreach($sendlog['goods'] as &$gv){
				$gv['title']=cfc('tools')->substr($gv['title'],0,6);
				$sendlog['goodsinfo'] .=$gv['title'];
				if($gv['selespename']){
					$sendlog['goodsinfo'] .='['.$gv['selespename'].']';
				}
				if($gv['leititle']){
					$sendlog['goodsinfo'] .='['.$gv['leititle'].']';
				}
				$sendlog['goodsinfo'] .="(".$gv['num'].")；";
				$gv['unit']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),'unit');
		}
		$times=$sendlog['day'].' '.$sendlog['times'];
		$message=array(
			'first'=>array('value'=>'您好!您的商品已经送达。',"color" => "#4a5077"),
			'keyword1'=>array('value'=>'SN'.$sendlog['id'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$sendlog['goodsinfo'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>date('Y-m-d H:i:s',$sendlog['createtime']),"color" => "#4a5077"),
			'keyword4'=>array('value'=>$times,"color" => "#4a5077"),
			'keyword5'=>array('value'=>date('Y-m-d H:i:s'),"color" => "#4a5077"),
			'remark'=>array('value'=>'感谢您的支持与厚爱。',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>'SN'.$sendlog['id']),
			array('value'=>$sendlog['goodsinfo']),
			array('value'=>date('Y-m-d H:i:s',$sendlog['createtime'])),
			array('value'=>$times),
			array('value'=>date('Y-m-d H:i:s')),
		);
		$url=custom_url('jy_peimilk/member.sendlog/',true);
		cfc('account')->sendtwoNotice($sendlog['buymid'],$template_id,$message,$url,'receive2buyer','jy_weishop');
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_peimilk/member/sendlog/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($sendlog['buymid'],$wxapptemplate_id,$wxappmsg,$url,'receive2buyer','jy_weishop');
		}
	}
	public function notice_check_apply($apply,$url=''){
		//审核通过
		$member=$this->get('member',array('id'=>$apply['pid'],'uniacid'=>$_SESSION['uniacid']));
		$template_id=cfc('account')->get_tpl_template_id('OPENTM408250107','申请成功通知');
		$message=array(
			'first'=>array('value'=>'申请成为配送员，审核通过！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$member['title'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$member['mobile'],"color" => "#4a5077"),
			'remark'=>array('value'=>'感谢你的使用。',"color" => "#4a5077"),
		);
		if(!$url){
			$url=custom_url('jy_peimilk/index/',true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($member['mid'],$template_id,$message,$url,'check_apply','jy_peimilk',$order_id);
		}
	}
}